<?php
if(!isset($_GET['StudentID'])){
    header("location:Students.php"); //跳转到学生页面
}else{
    $StudentID = $_GET['StudentID'];
    require 'Conn.php';
    
    $sql="SELECT * FROM student where StudentID='$StudentID'";  
    $result = $db->query($sql);
    if($result){
        $rows = $result->fetch_assoc();
        print_r(explode('，',$rows['Hobby']));
        var_dump(in_array('阅读',explode('，',$rows['Hobby'])));
    }
    /*
    $sql="SELECT * FROM student where StudentID=?"; //参数以？代替
    $stmt=$db->prepare($sql); //预处理
    $stmt->bind_param('s',$StudentID); //绑定参数
    $stmt->bind_result($StudentID,$StudentName,$Password,$ClassNo,$Sex,$Hobby,$Mobile,$Email,$Photo);
    $stmt->execute(); //执行查询
    $rows = $stmt->fetch();
    echo $StudentName;
    */
    $db->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生信息修改</title>
    <style type="text/css">
        body{
            margin:0px;
            text-align:center;
        }
        #reg{
            width:370px;
            border:1px solid blue;
            line-height:40px;
            margin:0 auto;
            padding-left:100px;
            padding-top:15px;
            padding-bottom:15px;
            text-align:left;
            font-size:14px;
        }
</style>
</head>
<body>
    <?php
        include_once "HeaderNav.html";  //引入头部
    ?>
    <h1>学生信息修改</h1>
    <form action="UpdateData.php" method="post"  enctype="multipart/form-data">
    <div id="reg">
        <div>学号：<input type="text" name="stuNo" value="<?php if(isset($rows['StudentID'])) echo $rows['StudentID'] ?>" readonly /></div>
        <div>姓名：<input type="text" name="stuName" value="<?php if(isset($rows['StudentName'])) echo $rows['StudentName'] ?>" /></div>
        <div>密码：<input type="password" name="pwd" value="<?php if(isset($rows['Password'])) echo $rows['Password'] ?>" /></div>
        <div style="margin-left:-28px;">确认密码：<input type="password" name="confirmPwd"/></div>
        <div>班级：<select name="className">
                    <option value='20180101'>18软件1班</option>
                    <option value='20180102'>18软件2班</option>
                    <option value='20180103'>18软件3班</option>
                    <option value='20180104'>18软件4班</option>
                    <option value='20180201'>18应用1班</option>
                    <option value='20180202'>18应用2班</option>
                    <option value='20180301'>18电气1班</option>
                    <option value='20180302'>18电气2班</option>    
                </select>
        </div>
        <div>性别：<input type="radio" name="sex" value="男" <?php if(isset($rows['Sex']) && $rows['Sex']=='男') echo 'checked' ?> >男
                  <input type="radio" name="sex" value="女" <?php if(isset($rows['Sex']) && $rows['Sex']=='女') echo 'checked' ?> >女
        </div>
        <div>爱好：<input type="checkbox" name="hobby[]" value="阅读" <?php if(in_array('阅读',explode('，',$rows['Hobby']))) echo 'checked' ?> />阅读
                <input type="checkbox" name="hobby[]" value="运动" <?php if(in_array('运动',explode('，',$rows['Hobby']))) echo 'checked' ?>/>运动
                <input type="checkbox" name="hobby[]" value="电影" <?php if(in_array('电影',explode('，',$rows['Hobby']))) echo 'checked' ?>/>电影
                <input type="checkbox" name="hobby[]" value="音乐" <?php if(in_array('音乐',explode('，',$rows['Hobby']))) echo 'checked' ?>/>音乐
        </div>
        <div style="margin-left: 42px;margin-top:-12px;">
                <input type="checkbox" name="hobby[]" value="旅游" <?php if(in_array('旅游',explode('，',$rows['Hobby']))) echo 'checked' ?>/>旅游
                <input type="checkbox" name="hobby[]" value="上网" <?php if(in_array('上网',explode('，',$rows['Hobby']))) echo 'checked' ?>/>上网
        </div>
        <div>手机：<input type="text" name="mobile" value="<?php if(isset($rows['Mobile'])) echo $rows['Mobile'] ?>" /></div>
        <div>邮箱：<input type="text" name="email" value="<?php if(isset($rows['Email'])) echo $rows['Email'] ?>" /></div>
        <div>相片：<input type="file" name="photo"/><br/>*上传文件大小不要超过2M，必须是.jpg、.gif、.png类型</div>
        <div style="margin-left:85px;">
            <input type="submit" name="btnSubmit" value="修改"/>
        </div>
    </div>
    </form>
    <?php
        include_once "Footer.html";  //引入脚部
    ?>
</body>
</html>